package com.ychs.dpmms.service;

import com.ychs.dpmms.dao.SecondOrganizationMapper;
import com.ychs.dpmms.entity.SecondOrganization;
import com.ychs.dpmms.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * copyright(c)2021 YYB.ALL rights Reserved
 * <p>
 * 描述:二级基层党组织service实现类
 *
 * @author 原玉波
 * @version 1.0
 * @date 2021/8/13
 */
@Service
public class SecondOrganizationService implements IBaseService<SecondOrganization>{

    //slf4j日志对象
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    //引入mapper
    @Resource
    private SecondOrganizationMapper mapper;

    /**
     * 添加记录
     *
     * @param secondOrganization 记录对象
     * @return 是否添加成功
     */
    @Override
    public boolean add(SecondOrganization secondOrganization) {
        boolean result = mapper.insert(secondOrganization) == Constants.UPDATE_SUCCESS;
        return result;
    }

    /**
     * 修改记录
     *
     * @param secondOrganization 记录对象
     * @return 是否修改成功
     */
    @Override
    public boolean modify(SecondOrganization secondOrganization) {
        boolean result = mapper.update(secondOrganization) == Constants.UPDATE_SUCCESS;
        return result;
    }

    /**
     * 删除记录
     *
     * @param id 该记录的id
     * @return 是否删除成功
     */
    @Override
    public boolean remove(int id) {
        boolean result = mapper.delete(id) == Constants.UPDATE_SUCCESS;
        return result;
    }

    /**
     * 按照条件查询所有记录
     *
     * @param conditions 条件
     * @return 记录对象
     */
    @Override
    public List<SecondOrganization> search(Map<String, Object> conditions) {
        List<SecondOrganization> secondOrganizations
                = mapper.select(conditions);
        return secondOrganizations;
    }

    /**
     * 按照id查询记录
     *
     * @param id 记录的id
     * @return 记录对象
     */
    @Override
    public SecondOrganization searchById(int id) {
        SecondOrganization secondOrganization = mapper.selectById(id);
        return secondOrganization;
    }

    /**
     * 按照条件查询记录总数
     *
     * @param conditions 条件
     * @return 符合条件的记录总数
     */
    @Override
    public int searchTotalNumber(Map<String, Object> conditions) {
        int count = mapper.selectTotalNumber(conditions);
        return count;
    }
}
